require('dotenv').config();
var path = require('path');
var express = require('express');
var app = express();
var bodyParser = require('body-parser');

const SERVER_PORT = process.env.PORT || 9999;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true,limit: '1mb'}));
app.use('/', express.static(path.join(__dirname, 'public')));
app.get('*', function (request, response){
  response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
app.use(function(req, res, next) {
  res.setHeader('Access-Control-Allow-Origin', '*');
  res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  res.setHeader("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
  next();
});

app.listen(SERVER_PORT, function(){
    console.log(`Server is now running on http://localhost:${SERVER_PORT}`)
});